package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.app.Dialog;
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.UriUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.stark.picselect.config.PhotoConfig;
import com.stark.picselect.entity.SelectMediaEntity;
import com.stark.picselect.utils.MediaLoadManager;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.VideoAdapter;
import flc.ast.bean.MyVideoBean;
import flc.ast.databinding.ActivityLocalVideoBinding;
import flc.ast.utils.AppSpUtils;
import flc.ast.utils.Content;
import io.reactivex.rxjava3.core.ObservableEmitter;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.FileP2pUtil;
import stark.common.basic.utils.FileUtil;
import stark.common.basic.utils.MediaUtil;
import stark.common.basic.utils.RxUtil;
import stark.common.basic.utils.StkPermissionHelper;
import stark.common.basic.utils.TimeUtil;
import stark.common.basic.utils.UriUtil;
import stark.common.basic.view.container.StkLinearLayout;

public class LocalVideoActivity extends BaseAc<ActivityLocalVideoBinding> {

    private VideoAdapter videoAdapter;
    private List<MyVideoBean> listAll = new ArrayList<>();//全部数据
    private List<MyVideoBean> listImport = new ArrayList<>();//导入的视频
    private List<MyVideoBean> listShow = new ArrayList<>();//搜索后展示的数据
    private Dialog myMoreDialog;
    private TextView sortText;
    private int position = 0;//选择排序方式
    private String[] SortStr;
    private Dialog myAddPlayDialog;
    private TextView addPlayTip;
    private Dialog myEncipherDialog;
    private TextView encipherTip;
    private Dialog myVideoMoreDialog;
    private Dialog myRenameDialog;
    private EditText dialogRename;
    private Dialog myDeleteDialog;
    private int selPosition = -1;
    private String selPath = "";
    private String selUri = "";
    private long selSize;
    private MyVideoBean selVideo;
    private List<String> listShare = new ArrayList<>();//分享的集合
    private boolean isEdit = false;
    private Dialog myInfoDialog;
    private TextView infoText1, infoText2, infoText3, infoText4, infoText5, infoText6, infoText7;
    private boolean isAll = false;
    private List<MyVideoBean> listSel = new ArrayList<>();//选择的集合
    private List<MyVideoBean> listDel = new ArrayList<>();//删除的集合

    @Override
    protected int onCreate() {
        return R.layout.activity_local_video;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);
        mDataBinding.ivLocalVideoBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.ivLocalVideoSearch.setOnClickListener(this);
        mDataBinding.ivLocalVideoMore.setOnClickListener(this);
        mDataBinding.tvSelCancel.setOnClickListener(this);
        mDataBinding.ivAllSel.setOnClickListener(this);
        mDataBinding.tvEditAddPlayList.setOnClickListener(this);
        mDataBinding.tvEditSaveEncipher.setOnClickListener(this);
        mDataBinding.tvEditShare.setOnClickListener(this);
        mDataBinding.tvEditDelete.setOnClickListener(this);
        mDataBinding.rvLocalVideoList.setLayoutManager(new GridLayoutManager(mContext, 2));
        videoAdapter = new VideoAdapter();
        mDataBinding.rvLocalVideoList.setAdapter(videoAdapter);
        videoAdapter.addChildClickViewIds(R.id.ivVideoItemMore);
        videoAdapter.setOnItemClickListener(this);
        videoAdapter.setOnItemChildClickListener(this);
        moreDialog();
        deleteDialog();
        renameDialog();
        infoDialog();
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivLocalVideoSearch:
                searchVideo();
                break;
            case R.id.ivLocalVideoMore:
                myMoreDialog.show();
                break;
            case R.id.llDialogMoreSel://多选处理
                isEdit = true;
                videoAdapter.setEdit(true);
                videoAdapter.notifyDataSetChanged();
                mDataBinding.rlLocalVideoTitle.setVisibility(View.GONE);
                mDataBinding.rlLocalVideoAllSel.setVisibility(View.VISIBLE);
                mDataBinding.llLocalVideoBottomView.setVisibility(View.VISIBLE);
                myMoreDialog.dismiss();
                break;
            case R.id.tvSelCancel:
                cancelEdit();
                break;
            case R.id.ivAllSel://全选
                isAll = !isAll;
                mDataBinding.ivAllSel.setImageResource(isAll ? R.drawable.axuanzhong : R.drawable.aweixuanz);
                listSel.clear();
                for (MyVideoBean bean : videoAdapter.getValidData()) {
                    if (isAll) {
                        listSel.add(bean);
                    }
                    bean.setSelect(isAll);
                }
                videoAdapter.notifyDataSetChanged();
                break;
            case R.id.ivDialogMoreSort://排序
                mDataBinding.etLocalVideoSearch.setText("");
                videoAdapter.setText("");
                if (position == 0) {
                    position++;
                } else if (position == 1) {
                    position++;
                } else if (position == 2) {
                    position++;
                } else if (position == 3) {
                    position = 0;
                }
                sortText.setText(SortStr[position]);
                getData();
                break;
            case R.id.ivDialogMoreImport://文件导入
                gotoAlbum();
                myMoreDialog.dismiss();
                break;
            case R.id.tvEditAddPlayList://加入列表
                if (listSel.size() == 0) return;
                addPlayDialog();
                myAddPlayDialog.show();
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        PlayActivity.listPlay.clear();
                        PlayActivity.listPlay.addAll(listSel);
                        startActivity(PlayActivity.class);
                        myAddPlayDialog.dismiss();
                    }
                }, 1000);
                break;
            case R.id.tvEditSaveEncipher://存入加密
                if (listSel.size() == 0) return;
                listDel.clear();
                for (MyVideoBean bean : listSel) {
                    String resultFile = FileUtil.generateFilePath(Content.MyEnciper, ".mp4");
                    FileP2pUtil.copyToPrivate(Uri.parse(bean.getUrl()), resultFile);
                    listDel.add(bean);
                }
                encipherDialog();
                myEncipherDialog.show();
                break;
            case R.id.ivDialogEncipherRight:
                myEncipherDialog.dismiss();
                deleteVideo();
                break;
            case R.id.ivDialogEncipherCancel:
                myEncipherDialog.dismiss();
                break;
            case R.id.tvEditShare://分享
                if (listSel.size() == 0) return;
                listShare.clear();
                for (MyVideoBean bean : listSel) {
                    listShare.add(bean.getPath());
                }
                shareFile();
                break;
            case R.id.tvEditDelete://删除
                if (listSel.size() == 0) return;
                listDel.clear();
                for (MyVideoBean bean : listSel) {
                    listDel.add(bean);
                }
                myDeleteDialog.show();
                break;
            case R.id.ivDialogDeleteCancel://取消
                myDeleteDialog.dismiss();
                break;
            case R.id.ivDialogDeleteRight://确定
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                    if (Environment.isExternalStorageManager()) {
                        deleteVideo();
                    } else {
                        try {
                            Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
                            intent.setData(Uri.parse("package:" + getPackageName()));
                            startActivityForResult(intent, 100);
                        } catch (Exception e) {
                            Intent intent = new Intent();
                            intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
                            startActivityForResult(intent, 100);
                        }
                    }
                } else {
                    deleteVideo();
                }
                break;
            case R.id.tvDialogVideoMoreRename://重命名
                myVideoMoreDialog.dismiss();
                dialogRename.setText("");
                myRenameDialog.show();
                break;
            case R.id.ivDialogRenameRight:
                myRenameDialog.dismiss();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                    if (Environment.isExternalStorageManager()) {
                        renameVideo();
                    } else {
                        try {
                            Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
                            intent.setData(Uri.parse("package:" + getPackageName()));
                            startActivityForResult(intent, 100);
                        } catch (Exception e) {
                            Intent intent = new Intent();
                            intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
                            startActivityForResult(intent, 100);
                        }
                    }
                } else {
                    renameVideo();
                }
                break;
            case R.id.ivDialogRenameCancel:
                myRenameDialog.dismiss();
                break;
            case R.id.tvDialogVideoMoreShare://单个分享
                myVideoMoreDialog.dismiss();
                listShare.clear();
                listShare.add(selPath);
                shareFile();
                break;
            case R.id.tvDialogVideoMoreEncipher://单个加入加密
                String resultFile = FileUtil.generateFilePath(Content.MyEnciper, ".mp4");
                FileP2pUtil.copyToPrivate(Uri.parse(selVideo.getUrl()), resultFile);
                myVideoMoreDialog.dismiss();
                ToastUtils.showShort(getText(R.string.add_suc));
                break;
            case R.id.tvDialogVideoMoreInfo://信息
                myVideoMoreDialog.dismiss();
                setInfo();
                break;
            case R.id.tvDialogVideoMoreDelete://单个删除
                myVideoMoreDialog.dismiss();
                listDel.clear();
                listDel.add(selVideo);
                myDeleteDialog.show();
                break;
        }
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        if (isEdit) {
            if (videoAdapter.getItem(position).isSelect()) {
                videoAdapter.getItem(position).setSelect(false);
                listSel.remove(videoAdapter.getItem(position));
            } else {
                videoAdapter.getItem(position).setSelect(true);
                listSel.add(videoAdapter.getItem(position));
            }
            videoAdapter.notifyItemChanged(position);
            isAllSel();
        } else {
            selPosition = position;
            List<MyVideoBean> list = new ArrayList<>();
            list.add(videoAdapter.getItem(position));
            PlayActivity.listPlay = list;
            startActivity(PlayActivity.class);
        }
    }

    @Override
    public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
        switch (view.getId()) {
            case R.id.ivVideoItemMore://更多
                selPath = videoAdapter.getItem(position).getPath();
                selUri = videoAdapter.getItem(position).getUrl();
                selSize = videoAdapter.getItem(position).getSize();
                selVideo = videoAdapter.getItem(position);
                videoMoreDialog();
                myVideoMoreDialog.show();
                break;
        }
    }

    @Override
    protected void initData() {
        getPermission();
        //排序
        SortStr = new String[]{getString(R.string.sort_text1), getString(R.string.sort_text2), getString(R.string.sort_text3), getString(R.string.sort_text4)};
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (selPosition != -1) {
            videoAdapter.getItem(selPosition).setSelect(false);
            selPosition = -1;
        }
    }

    //获取权限
    private void getPermission() {
        StkPermissionHelper.permission(StkPermissionHelper.Permission.ACCESS_IMAGE_VIDEO).reqPermissionDesc(getString(R.string.get_storage_permission)).callback(new StkPermissionHelper.ACallback() {
            @Override
            public void onGranted() {
                getData();
            }

            @Override
            public void onDenied(boolean needGoSettings) {
                mDataBinding.rvLocalVideoList.setVisibility(View.GONE);
                mDataBinding.ivLocalVideoNoData.setVisibility(View.VISIBLE);
            }
        }).request();
    }

    //获取视频和图片数据
    private void getData() {
        listAll.clear();
        listShow.clear();
        RxUtil.create(new RxUtil.Callback<List<SelectMediaEntity>>() {
            @Override
            public void doBackground(ObservableEmitter<List<SelectMediaEntity>> emitter) {
                List<SelectMediaEntity> listSys = MediaLoadManager.loadAllMediaData(mContext, PhotoConfig.Mode.VIDEO);
                emitter.onNext(listSys);
            }

            @Override
            public void accept(List<SelectMediaEntity> selectMediaEntities) {
                if (selectMediaEntities.size() > 0) {
                    for (SelectMediaEntity bean : selectMediaEntities) {
                        listAll.add(new MyVideoBean(bean.getMediaName(), bean.getPath(), bean.getUri(), bean.getDuration(), FileUtils.getFileLastModified(bean.getPath()), bean.getSize(), false));
                    }
                    listAll.addAll(listImport);
                    if (position == 0) {
                        listSort1();
                    } else if (position == 1) {
                        listSort2();
                    } else if (position == 2) {
                        listSort3();
                    } else if (position == 3) {
                        listSort4();
                    }
                    mDataBinding.rvLocalVideoList.setVisibility(View.VISIBLE);
                    mDataBinding.ivLocalVideoNoData.setVisibility(View.GONE);
                } else {
                    mDataBinding.rvLocalVideoList.setVisibility(View.GONE);
                    mDataBinding.ivLocalVideoNoData.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    //搜索视频
    private void searchVideo() {
        String text = mDataBinding.etLocalVideoSearch.getText().toString();
        if (TextUtils.isEmpty(text)) {
            videoAdapter.setList(listAll);
            videoAdapter.setText("");
        } else {
            listShow.clear();
            for (MyVideoBean bean : listAll) {
                if (bean.getName().contains(text)) {
                    listShow.add(bean);
                }
            }
            videoAdapter.setList(listShow);
            videoAdapter.setText(text);
        }
        if (listShow.size() > 0) {
            mDataBinding.rvLocalVideoList.setVisibility(View.VISIBLE);
            mDataBinding.ivLocalVideoNoData.setVisibility(View.GONE);
        } else {
            mDataBinding.rvLocalVideoList.setVisibility(View.GONE);
            mDataBinding.ivLocalVideoNoData.setVisibility(View.VISIBLE);
        }
        videoAdapter.notifyDataSetChanged();
    }

    //删除视频
    private void deleteVideo() {
        myDeleteDialog.dismiss();
        showDialog(getString(R.string.delete_ing));
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                RxUtil.create(new RxUtil.Callback<String>() {
                    @Override
                    public void doBackground(ObservableEmitter<String> emitter) {
                        for (int i = 0; i < listDel.size(); i++) {
                            if (listImport.contains(listDel.get(i))) {
                                listImport.remove(listDel.get(i));
                            }
                            mContext.getContentResolver().delete(Uri.parse(listDel.get(i).getUrl()), null, null);
                        }
                        emitter.onNext("");
                    }

                    @Override
                    public void accept(String path) {
                        dismissDialog();
                        cancelEdit();
                        getData();
                    }
                });
            }
        }, 500);
    }

    //重命名视频
    private void renameVideo() {
        String name = dialogRename.getText().toString();
        if (TextUtils.isEmpty(name)) {
            ToastUtils.showShort(R.string.please_input_name);
            return;
        }
        showDialog(getString(R.string.rename_ing));
        RxUtil.create(new RxUtil.Callback<String>() {
            @Override
            public void doBackground(ObservableEmitter<String> emitter) {
                String suffix = selPath.substring(selPath.lastIndexOf("."));
                FileUtils.rename(selPath, name + suffix);
                String newFilePath = FileUtils.getDirName(selPath + name + suffix);
                emitter.onNext(newFilePath);
            }

            @Override
            public void accept(String path) {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        dismissDialog();
                        getData();
                    }
                },2000);
            }
        });
    }

    //设置信息
    private void setInfo() {
        infoText1.setText(FileUtils.getFileName(selPath));
        infoText2.setText(FileUtils.getFileByPath(selPath).getAbsolutePath());
        String size1 = ConvertUtils.byte2FitMemorySize(selSize, 1);
        String size2 = "(" + selSize + getString(R.string.byte_text);
        infoText3.setText(size1 + " " + size2);
        infoText4.setText(TimeUtils.millis2String(FileUtils.getFileLastModified(selPath), new SimpleDateFormat("yyyy年MM月dd日 HH:mm")));
        infoText5.setText(FileUtils.getFileExtension(selPath));
        infoText6.setText("");//分辨率不会
        infoText7.setText(TimeUtil.getMmss(MediaUtil.getDuration(selPath)));
        myInfoDialog.show();
    }

    //分享文件
    private void shareFile() {
        if (listShow.size() == 0) {
            ToastUtils.showShort(R.string.please_sel_share_file);
            return;
        }
        // 创建一个 Intent 对象，并设置 Action 为 ACTION_SEND_MULTIPLE
        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType("*/*");
        // 将要分享的文件添加到 Intent 中
        ArrayList<Uri> uris = new ArrayList<>();
        for (String filePath : listShare) {
            File file = new File(filePath);
            Uri uri = FileProvider.getUriForFile(mContext, mContext.getPackageName() + ".provider", file);
            uris.add(uri);
        }
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        // 启动分享界面
        startActivity(Intent.createChooser(intent, "Share files"));
    }

    //取消编辑
    private void cancelEdit() {
        isEdit = false;
        videoAdapter.setEdit(false);
        mDataBinding.rlLocalVideoTitle.setVisibility(View.VISIBLE);
        mDataBinding.rlLocalVideoAllSel.setVisibility(View.GONE);
        mDataBinding.llLocalVideoBottomView.setVisibility(View.GONE);
        isAll = false;
        listSel.clear();
        for (MyVideoBean bean : videoAdapter.getValidData()) {
            bean.setSelect(false);
        }
        videoAdapter.notifyDataSetChanged();
    }

    //是否全选
    private void isAllSel() {
        if (listSel.size() == videoAdapter.getValidData().size()) {
            isAll = true;
            mDataBinding.ivAllSel.setImageResource(R.drawable.axuanzhong);
        } else {
            isAll = false;
            mDataBinding.ivAllSel.setImageResource(R.drawable.aweixuanz);
        }
    }

    //文件大小升序
    private void listSort1() {
        Collections.sort(listAll, new Comparator<MyVideoBean>() {
            @Override
            public int compare(MyVideoBean o1, MyVideoBean o2) {
                return (int) (o1.getSize() - o2.getSize());
            }
        });
        listShow.addAll(listAll);
        videoAdapter.setList(listShow);
    }

    //文件大小降序
    private void listSort2() {
        Collections.sort(listAll, new Comparator<MyVideoBean>() {
            @Override
            public int compare(MyVideoBean o1, MyVideoBean o2) {
                return (int) (o2.getSize() - o1.getSize());
            }
        });
        listShow.addAll(listAll);
        videoAdapter.setList(listShow);
    }

    //日期升序
    private void listSort3() {
        Collections.sort(listAll, new Comparator<MyVideoBean>() {
            @Override
            public int compare(MyVideoBean o1, MyVideoBean o2) {
                int flag;
                if (o1.getDate() > o2.getDate()) {
                    flag = 1;
                } else {
                    flag = -1;
                }
                return flag;
            }
        });
        listShow.addAll(listAll);
        videoAdapter.setList(listShow);
    }

    //日期降序
    private void listSort4() {
        Collections.sort(listAll, new Comparator<MyVideoBean>() {
            @Override
            public int compare(MyVideoBean o1, MyVideoBean o2) {
                int flag;
                if (o2.getDate() > o1.getDate()) {
                    flag = 1;
                } else {
                    flag = -1;
                }
                return flag;
            }
        });
        listShow.addAll(listAll);
        videoAdapter.setList(listShow);
    }

    //去到系统选择导入视频界面
    private void gotoAlbum() {
        Intent intent = new Intent();
        if (Build.VERSION.SDK_INT < 19) {
            intent.setAction(Intent.ACTION_GET_CONTENT);
        } else {
            intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
        }
        intent.setType("video/*");
        startActivityForResult(intent, Content.REQUEST_VIDEO_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == Content.REQUEST_VIDEO_CODE) {
            if (data != null) {
                //获取视频路径
                Uri uri = data.getData();
                File file = UriUtil.uri2File(uri);
                listImport.add(new MyVideoBean(file.getName(), file.getPath(), uri.toString(), MediaUtil.getDuration(file.getPath()), FileUtils.getFileLastModified(file.getPath()), file.length(), false));
                getData();
            }
        } else if (requestCode == 100 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            if (Environment.isExternalStorageManager()) {
                renameVideo();
            } else {
                ToastUtils.showShort(R.string.no_permission);
            }
        }
    }

    private void moreDialog() {
        myMoreDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_more, null);
        myMoreDialog.setContentView(inflate);
        myMoreDialog.setCancelable(true);
        Window dialogWindow = myMoreDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        StkLinearLayout moreSel = inflate.findViewById(R.id.llDialogMoreSel);
        sortText = inflate.findViewById(R.id.tvDialogMoreSort);
        ImageView sort = inflate.findViewById(R.id.ivDialogMoreSort);
        ImageView importImg = inflate.findViewById(R.id.ivDialogMoreImport);
        moreSel.setOnClickListener(this);
        sort.setOnClickListener(this);
        importImg.setOnClickListener(this);
    }

    //添加播放列表提示
    private void addPlayDialog() {
        myAddPlayDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_add_play, null);
        myAddPlayDialog.setContentView(inflate);
        myAddPlayDialog.setCancelable(true);
        Window dialogWindow = myAddPlayDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.8);
        lp.y = 50;
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        addPlayTip = inflate.findViewById(R.id.tvDialogAddPlayTip);
        addPlayTip.setText(listSel.size() + getString(R.string.add_play_tip1));
    }

    //存入加密提示
    private void encipherDialog() {
        myEncipherDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_encipher, null);
        myEncipherDialog.setContentView(inflate);
        myEncipherDialog.setCancelable(true);
        Window dialogWindow = myEncipherDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.8);
        lp.y = 50;
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        encipherTip = inflate.findViewById(R.id.tvDialogEncipherTip);
        ImageView dialogCancel = inflate.findViewById(R.id.ivDialogEncipherCancel);
        ImageView dialogConfirm = inflate.findViewById(R.id.ivDialogEncipherRight);
        encipherTip.setText(listSel.size() + getString(R.string.add_encipher_tip1));
        dialogCancel.setOnClickListener(this);
        dialogConfirm.setOnClickListener(this);
    }

    //删除提示
    private void deleteDialog() {
        myDeleteDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_delete, null);
        myDeleteDialog.setContentView(inflate);
        myDeleteDialog.setCancelable(true);
        Window dialogWindow = myDeleteDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.8);
        lp.y = 50;
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        ImageView dialogCancel = inflate.findViewById(R.id.ivDialogDeleteCancel);
        ImageView dialogConfirm = inflate.findViewById(R.id.ivDialogDeleteRight);
        dialogCancel.setOnClickListener(this);
        dialogConfirm.setOnClickListener(this);
    }

    private void videoMoreDialog() {
        myVideoMoreDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_video_more, null);
        myVideoMoreDialog.setContentView(inflate);
        myVideoMoreDialog.setCancelable(true);
        Window dialogWindow = myVideoMoreDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 1.0);
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        TextView rename = inflate.findViewById(R.id.tvDialogVideoMoreRename);
        TextView share = inflate.findViewById(R.id.tvDialogVideoMoreShare);
        TextView add = inflate.findViewById(R.id.tvDialogVideoMoreEncipher);
        TextView info = inflate.findViewById(R.id.tvDialogVideoMoreInfo);
        TextView delete = inflate.findViewById(R.id.tvDialogVideoMoreDelete);
        rename.setOnClickListener(this);
        share.setOnClickListener(this);
        add.setOnClickListener(this);
        info.setOnClickListener(this);
        delete.setOnClickListener(this);
    }

    //重命名弹框
    private void renameDialog() {
        myRenameDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_rename, null);
        myRenameDialog.setContentView(inflate);
        myRenameDialog.setCancelable(true);
        //获取当前Activity所在的窗体
        Window dialogWindow = myRenameDialog.getWindow();
        //设置Dialog从窗体中心弹出
        dialogWindow.setGravity(Gravity.CENTER);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.8);
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        ImageView dialogCancel = inflate.findViewById(R.id.ivDialogRenameCancel);
        ImageView dialogRight = inflate.findViewById(R.id.ivDialogRenameRight);
        dialogRename = inflate.findViewById(R.id.etDialogRenameText);
        dialogCancel.setOnClickListener(this);
        dialogRight.setOnClickListener(this);
    }

    //信息弹框
    private void infoDialog() {
        myInfoDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_info, null);
        myInfoDialog.setContentView(inflate);
        myInfoDialog.setCancelable(true);
        //获取当前Activity所在的窗体
        Window dialogWindow = myInfoDialog.getWindow();
        //设置Dialog从窗体中心弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 1.0);
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        StkLinearLayout dialogBg = inflate.findViewById(R.id.llDialogInfoBg);
        dialogBg.setBackgroundResource(R.drawable.shape_more);
        infoText1 = inflate.findViewById(R.id.tvDialogInfoText1);
        infoText2 = inflate.findViewById(R.id.tvDialogInfoText2);
        infoText3 = inflate.findViewById(R.id.tvDialogInfoText3);
        infoText4 = inflate.findViewById(R.id.tvDialogInfoText4);
        infoText5 = inflate.findViewById(R.id.tvDialogInfoText5);
        infoText6 = inflate.findViewById(R.id.tvDialogInfoText6);
        infoText7 = inflate.findViewById(R.id.tvDialogInfoText7);
    }

}